"""
`to_csv.py`
## 主要功能：
- 将`.txt`文件(数据之间以空格分隔)，转换为`.csv`(逗号分隔符)文件

> author: lhc
"""

if __name__ == '__main__':

    import pandas as pd

    f = open("./data/dwv_order_make_haikou_2.txt", "r", encoding='utf-8')
    columns = f.readline().split()

    train_data = pd.read_table('./data/dwv_order_make_haikou_2.txt', iterator=True, header=None)

    while True:
        try:
            chunk = train_data.get_chunk(5600000)
            chunk.columns = columns
            chunk.to_csv('./data/dwv_order_make_haikou_2.csv', mode='a', header=False, index=None)
        except Exception as e:
            break
